<?php
class CartPanel_ZonecostController extends Ext_Controller_SecureAction
{
    public function listAction()
	{
       	$model = new CartWS_Model_ZoneCost();
       	$this->view->paginator = new Ext_Paginator( 
       		$model->select(), 
       		$this->getRequest()->getParam('page') 
       	);
	}
    
    public function createAction()
    {
        $request = $this->getRequest();
        $form = new CartPanel_Form_ZoneCost();

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $model = new CartWS_Model_ZoneCostCost();
                $row = $model->createRow( $form->getValues() );
                $row->save();
				return $this->_helper->redirector('list');
            }
        }
        $this->view->form = $form;
    }

    public function updateAction()
    {
        $request = $this->getRequest();
        $form = new CartPanel_Form_ZoneCost();
		$model = new CartWS_Model_ZoneCost();
		$data = $model->find( $request->id )->current()	;
        if ($this->getRequest()->isPost()) {
            if ($form->isValid( $request->getPost() ) ) {
            	$data->setFromArray( $form->getValues() );
                $data->save();
                return $this->_helper->redirector('list');
            }
        } else {
        	$form->populate( $data);
      	}
        $this->view->form = $form;
    }
    
    public function deleteAction()
    {
		$model = new CartWS_Model_ShippingCost();
		$row = $model->find( $this->getRequest()->id )->current();
		if( $row != null ) {
			$row->locked =  ( $row->locked == 'T' ) ? 'F' : 'T';
			$row->end_date = ( $row->locked == 'T' ) ? Ext_Db_Date::now() : null ;
			$row->save();
		}
		return $this->_helper->redirector('list');
    }
}
